﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
    class Program
    {
        static public char[] permutation = new char[5];
        static public int bigCounter = 0; //na koi element ot permutaciqta sme
        static public int counter = 0; // broikata na permutaciite
        static void permutetionsDisplayer(StringBuilder elements)
        {
            if (elements.Length == 0) //ako simvolite ot koito moga da izbiram e prazen printiram
            {
                bigCounter--;
                printArray(permutation);
                return;
            }

            for (int index = 0; index < elements.Length; index++)
            {
                permutation[bigCounter] = elements[index]; //vzimam si element ot mesiva as elementi

                bigCounter++;
                StringBuilder swapElementArray = new StringBuilder(elements.ToString()); ;
                permutetionsDisplayer(swapElementArray.Remove(index, 1)); //maham element ot izbora i go prashtam
            }
            if (bigCounter > 0) //ako sme stignali v kraq na for mahame edin elements ot bigCounter
            {
                bigCounter--;
            }
        }
        static void printArray(char[] onePermutatio)
        {
            foreach (var item in onePermutatio)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
            counter++;
        }

        static void Main(string[] args)
        {
            StringBuilder a = new StringBuilder("12345");
            permutetionsDisplayer(a);
            Console.WriteLine(counter);

        }
    }
}
